package com.lanhai.fnstore.savestate;
 

import java.util.List;

import com.google.gson.Gson;
import com.lanhai.fnstore.Config;
import com.lanhai.fnstore.Tools;  

public class StatePushThread {
	boolean running;
	Thread  th;
	Gson gson;
	String stateurl;

	public StatePushThread(Config conf) {
		stateurl=conf.getStateurl();
		gson=new Gson();
	}
	
	
	public void Start() {
		
		running = true; 
		th = new Thread() {

			@Override
			public void run() {
				while (running) {
					try {
						List<StateData> lst = StateQueue.Pop();
						if (lst == null||lst.size()==0) {
							Thread.sleep(100);
						} else {
							try {
								StateTemp lt=new StateTemp();
								lt.setList(lst);
								 String  json=gson.toJson(lt);
								 Tools.post(stateurl, json); 
							} catch (Exception e1) {

							}
						}

					} catch (Exception e) {

					}
				}
			}

		};
		th.start();
	}

	public void Stop() {
		running = false;
	 
			try {
				th .interrupt();
				th  = null;
			} catch (Exception e) {

			}
		 
	}

}

class StateTemp{
	private List<StateData> list;

	public List<StateData> getList() {
		return list;
	}

	public void setList(List<StateData> list) {
		this.list = list;
	}
	
}